

function Promise2(fun){

    let callBack ;

    const resolve = () => {
        callBack();
    }
    const then = (cb) => {
        callBack = cb;
    };
    fun(resolve);
    return {
        then,
    };
}

function timeout(ms) {
  return new Promise2((resolve) => {
    setTimeout(resolve, ms, 'done');
  });
}
console.log('begin: ');
timeout(3000).then(() => {
  console.log('我3秒后被输出');
});

const fetchData = (url, cb) => {
    setTimeout(() => {
        const  data = { status: 200, data: url };
        cb(data)
    },1000);
}


const fetchDataPromisify = (url) => {
    return new Promise((resolve)=>{
        fetchData(url, (data) => {
            resolve(data);
        });
    })
}

const p = fetchDataPromisify('http://www.baidu.com');

p.then((data)=>{
    console.log(1,data);
})

p.then((data)=>{
    console.log(2, data);
})